<template>
  <div class="common-table">
    <el-table :data="tableData" style="width: 100%" max-height="650" stripe v-loading="config.loading">
      <el-table-column label="序号" width="85">
        <template slot-scope="scope">
          <span >{{ (config.page - 1) * 20 + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip v-for="item in tableLabel" :key="item.prop" :label="item.label"
                       :width="item.width ? item.width : 125">
        <template slot-scope="scope">
          <span >{{ scope.row[item.prop] }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="180">
        <template slot-scope="scope">
          <el-button type="primary"  icon="el-icon-edit" @click="handleEdit(scope.row)"
                     circle></el-button>
          <el-button type="danger" v-per="'delete'" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     circle></el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination class="fr"
                   background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :total="config.total"
            :current-page.sync="config.page"
            :page-sizes="[10, 30, 50]"
            :page-size.sync="config.pageSize"
            layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>

</template>

<script>
export default {
  props: {
    tableData: Array,
    tableLabel: Array,
    config: Object
  },
  methods: {
    handleSizeChange(pageSize) {
      this.$emit('changePage', pageSize)
    },
    handleCurrentChange(page) {
      this.$emit('changePage', page)
    },
    handleEdit(row) {
      this.$emit('edit', row)
    },
    handleDelete(row) {
      this.$emit('del', row)
    },
    handleSave(row) {
      this.$emit('save', row)
    }
  }
}
</script>

<style lang="scss" scoped>
.common-table {
  height: calc(100% - 62px) !important;
  background-color: #fff;
  position: relative;
}
</style>
